# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
# https://github.com/romkatv/powerlevel10k#installation
# config exec  p10k configure
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

source /usr/share/zsh/share/antigen.zsh
# deepin theme argonaut
# font monaco


### two
#https://gitee.com/mirrors/nerd-fonts
#https://www.nerdfonts.com/#home
# 字体加\u e755:飞鸟 f0e7:闪电 e780:火 f054:箭头 



# 加载oh-my-zsh库
antigen use oh-my-zsh

# 加载原版oh-my-zsh中的功能(robbyrussell's oh-my-zsh).
# oh-my-zsh  plugins   https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins
antigen bundle git
antigen bundle gitfast
antigen bundle gitignore
antigen bundle git-auto-fetch
antigen bundle git-escape-magic
antigen bundle git-extras
antigen bundle git-flow-avh
antigen bundle git-prompt
antigen bundle github
antigen bundle pip
antigen bundle lein
antigen bundle heroku
antigen bundle fzf
antigen bundle tmux
antigen bundle autojump
antigen bundle golang
antigen bundle gradle
antigen bundle docker
antigen bundle docker-compose
antigen bundle command-not-found
antigen bundle man
antigen bundle mvn
antigen bundle ufw
antigen bundle vagrant
antigen bundle vagrant-prompt
antigen bundle virtualenv
antigen bundle virtualenvwrappe
antigen bundle vscode
#antigen bundle yarn
antigen bundle soimort/you-get



# 语法高亮功能
antigen bundle zsh-users/zsh-syntax-highlighting

# 代码提示功能
antigen bundle zsh-users/zsh-autosuggestions

# 自动补全功能
antigen bundle zsh-users/zsh-completions

# 历史搜索 
antigen bundle zsh-users/zsh-history-substring-search
# you-get
antigen bundle soimort/you-get


# 加载主题
#antigen theme robbyrussell
antigen theme romkatv/powerlevel10k powerlevel10k



# 保存更改
antigen apply

# === 命令别称
eval $(thefuck --alias)
alias s="TERM=xterm-256color zssh"
alias r="ranger"
alias cman='man -M /usr/share/man/zh_CN'
alias rdp='rdesktop -g 80%   -z  -a 24  -P -N -x 0x80  -r clipboard:PRIMARYCLIPBOARD  -r disk:h=/home/sky -r sound:on'

alias sml200=' smbclient   //192.168.2.200/share/ -A  /home/sky/.config/smb/auth'
alias smm='sudo mount  //192.168.2.200/share /mnt/sb -o username=Administrator,password=Coconet1.'
alias vim="TERM=xterm-256color  /usr/bin/vim"
alias unzipc="unzip -O GBK"
[[ $TMUX = "" ]] && export TERM="xterm-256color"
alias sl='sl | lolcat'

# fzf 设置
export FZF_DEFAULT_COMMAND="fd --exclude={.git,.idea,.vscode,.sass-cache,target,node_modules,build} --type f"

export FZF_DEFAULT_COMMAND="fd --type file --color=always"
export FZF_DEFAULT_OPTS='--height 40% --ansi  --reverse --border --preview "[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (bat --style=numbers --color=always {} || highlight -O ansi -l {} || cat {}) 2> /dev/null | head -500"'
# \ 弹出fzf 默认** 然后按tab 
export FZF_COMPLETION_TRIGGER='\'

# fzf tmux 高度
# export FZF_TMUX_HEIGHT='80%'
# <c-r> 弹出指令历史
# <c-t> 弹出路径搜索

#autojump
[[ -s /etc/profile.d/autojump.sh ]] && . /etc/profile.d/autojump.sh

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

#source /usr/share/autoenv-git/activate.sh
source /usr/share/nvm/init-nvm.sh





## vs
#compdef _vsp vsp

# zsh completion for vsp                                  -*- shell-script -*-

__vsp_debug()
{
    local file="$BASH_COMP_DEBUG_FILE"
    if [[ -n ${file} ]]; then
        echo "$*" >> "${file}"
    fi
}

_vsp()
{
    local shellCompDirectiveError=1
    local shellCompDirectiveNoSpace=2
    local shellCompDirectiveNoFileComp=4
    local shellCompDirectiveFilterFileExt=8
    local shellCompDirectiveFilterDirs=16

    local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace
    local -a completions

    __vsp_debug "\n========= starting completion logic =========="
    __vsp_debug "CURRENT: ${CURRENT}, words[*]: ${words[*]}"

    # The user could have moved the cursor backwards on the command-line.
    # We need to trigger completion from the $CURRENT location, so we need
    # to truncate the command-line ($words) up to the $CURRENT location.
    # (We cannot use $CURSOR as its value does not work when a command is an alias.)
    words=("${=words[1,CURRENT]}")
    __vsp_debug "Truncated words[*]: ${words[*]},"

    lastParam=${words[-1]}
    lastChar=${lastParam[-1]}
    __vsp_debug "lastParam: ${lastParam}, lastChar: ${lastChar}"

    # For zsh, when completing a flag with an = (e.g., vsp -n=<TAB>)
    # completions must be prefixed with the flag
    setopt local_options BASH_REMATCH
    if [[ "${lastParam}" =~ '-.*=' ]]; then
        # We are dealing with a flag with an =
        flagPrefix="-P ${BASH_REMATCH}"
    fi

    # Prepare the command to obtain completions
    requestComp="${words[1]} __complete ${words[2,-1]}"
    if [ "${lastChar}" = "" ]; then
        # If the last parameter is complete (there is a space following it)
        # We add an extra empty parameter so we can indicate this to the go completion code.
        __vsp_debug "Adding extra empty parameter"
        requestComp="${requestComp} \"\""
    fi

    __vsp_debug "About to call: eval ${requestComp}"

    # Use eval to handle any environment variables and such
    out=$(eval ${requestComp} 2>/dev/null)
    __vsp_debug "completion output: ${out}"

    # Extract the directive integer following a : from the last line
    local lastLine
    while IFS='\n' read -r line; do
        lastLine=${line}
    done < <(printf "%s\n" "${out[@]}")
    __vsp_debug "last line: ${lastLine}"

    if [ "${lastLine[1]}" = : ]; then
        directive=${lastLine[2,-1]}
        # Remove the directive including the : and the newline
        local suffix
        (( suffix=${#lastLine}+2))
        out=${out[1,-$suffix]}
    else
        # There is no directive specified.  Leave $out as is.
        __vsp_debug "No directive found.  Setting do default"
        directive=0
    fi

    __vsp_debug "directive: ${directive}"
    __vsp_debug "completions: ${out}"
    __vsp_debug "flagPrefix: ${flagPrefix}"

    if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
        __vsp_debug "Completion received error. Ignoring completions."
        return
    fi

    while IFS='\n' read -r comp; do
        if [ -n "$comp" ]; then
            # If requested, completions are returned with a description.
            # The description is preceded by a TAB character.
            # For zsh's _describe, we need to use a : instead of a TAB.
            # We first need to escape any : as part of the completion itself.
            comp=${comp//:/\\:}

            local tab=$(printf '\t')
            comp=${comp//$tab/:}

            __vsp_debug "Adding completion: ${comp}"
            completions+=${comp}
            lastComp=$comp
        fi
    done < <(printf "%s\n" "${out[@]}")

    if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
        __vsp_debug "Activating nospace."
        noSpace="-S ''"
    fi

    if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
        # File extension filtering
        local filteringCmd
        filteringCmd='_files'
        for filter in ${completions[@]}; do
            if [ ${filter[1]} != '*' ]; then
                # zsh requires a glob pattern to do file filtering
                filter="\*.$filter"
            fi
            filteringCmd+=" -g $filter"
        done
        filteringCmd+=" ${flagPrefix}"

        __vsp_debug "File filtering command: $filteringCmd"
        _arguments '*:filename:'"$filteringCmd"
    elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
        # File completion for directories only
        local subDir
        subdir="${completions[1]}"
        if [ -n "$subdir" ]; then
            __vsp_debug "Listing directories in $subdir"
            pushd "${subdir}" >/dev/null 2>&1
        else
            __vsp_debug "Listing directories in ."
        fi

        local result
        _arguments '*:dirname:_files -/'" ${flagPrefix}"
        result=$?
        if [ -n "$subdir" ]; then
            popd >/dev/null 2>&1
        fi
        return $result
    else
        __vsp_debug "Calling _describe"
        if eval _describe "completions" completions $flagPrefix $noSpace; then
            __vsp_debug "_describe found some completions"

            # Return the success of having called _describe
            return 0
        else
            __vsp_debug "_describe did not find completions."
            __vsp_debug "Checking if we should do file completion."
            if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
                __vsp_debug "deactivating file completion"

                # We must return an error code here to let zsh know that there were no
                # completions found by _describe; this is what will trigger other
                # matching algorithms to attempt to find completions.
                # For example zsh can match letters in the middle of words.
                return 1
            else
                # Perform file completion
                __vsp_debug "Activating file completion"

                # We must return the result of this command, so it must be the
                # last command, or else we must store its result to return it.
                _arguments '*:filename:_files'" ${flagPrefix}"
            fi
        fi
    fi
}

# don't run the completion function when being source-ed or eval-ed
if [ "$funcstack[1]" = "_vsp" ]; then
	_vsp
fi

___MY_VMOPTIONS_SHELL_FILE="${HOME}/.jetbrains.vmoptions.sh"; if [ -f "${___MY_VMOPTIONS_SHELL_FILE}" ]; then . "${___MY_VMOPTIONS_SHELL_FILE}"; fi

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
